package com.ytf.auth.controller;

import com.ytf.core.common.Resp;
import com.ytf.core.web.application.UserAppService;
import com.ytf.core.web.pojo.dto.UserDto;
import lombok.AllArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YTF
 * @className RegisterController
 * @date 2025/5/24 11:08
 * @description
 */
@RestController
@RequestMapping("/register")
@AllArgsConstructor
public class RegisterController {

    private final PasswordEncoder passwordEncoder;
    private final UserAppService userAppService;

    @PostMapping
    public Resp<Void> insert(@RequestBody UserDto UserDto){
        UserDto.setPassword(passwordEncoder.encode(UserDto.getPassword()));
        Boolean aBoolean = userAppService.insert(UserDto);
        return aBoolean ? Resp.success():Resp.error();
    }

}
